package eu.jpereira.trainings.designpatterns.structural.decorator.channel.decorator;

import java.util.HashMap;
import java.util.Map;

import eu.jpereira.trainings.designpatterns.structural.decorator.channel.SocialChannel;

public class WordCensor extends SocialChannelDecorator
{
    protected Map<String, String> words;

    public WordCensor()
    {
        this.words = new HashMap<String, String>();
    }

    public WordCensor(SocialChannel decoratedChannel)
    {
        this.delegate = decoratedChannel;
        this.words = new HashMap<String, String>();
    }

    public void censorWord(String word, String replacement)
    {
        this.words.put(word, replacement);
    }

    @Override
    public void deliverMessage(String message)
    {
        for (Map.Entry<String, String> entry : this.words.entrySet())
        {
            message = message.replace(entry.getKey(), entry.getValue());
        }
        this.delegate.deliverMessage(message);
    }
}
